#include "../DistortMap.fxh"

uniform const texture2D Texture;
uniform const float4x4 World;
uniform const float4x4 LightMatrix;

sampler2D DiffuseTextureSampler = sampler_state
{
    Texture = <Texture>;
    MinFilter = linear;
    MagFilter = linear;
    MipFilter = linear;
    MipMapLODBias = -1.5f;
    AddressU = WRAP;
    AddressV = WRAP;
    AddressW = WRAP;
};


struct VertexInputShadow
{
	float4 Position		: POSITION0;
	float2 texCoord		: TEXCOORD0;
};


struct VertexOutputShadow
{
	float4 Position		: POSITION0;
	float4 texCoord			: TEXCOORD0;
};

struct PixelShaderShadowOutput
{
    half4 Depth : COLOR0;
};

VertexOutputShadow VertexShaderShadow(VertexInputShadow input)
{   
	VertexOutputShadow output;

	output.Position	= mul(input.Position,World);
	output.Position	= mul(output.Position,LightMatrix);
	output.Position.xyz	= Distort(LightMatrix,output.Position.xyz);



	output.texCoord.xy	= input.texCoord.xy;
	output.texCoord.zw	= output.Position.zw;

	return output;
}
PixelShaderShadowOutput PS_CreateShadowMap(VertexOutputShadow input)
{
	PixelShaderShadowOutput output;
	float4 diffuseTexture = tex2D(DiffuseTextureSampler,input.texCoord.xy);
	clip(diffuseTexture.a - 0.7);
	
	float4 outColor = float4(input.texCoord.z,0,0,1);
	output.Depth = outColor;
	return output;
}
technique CreateShadowMap
{
    pass
    {
		CullMode	= NONE;//CCW;
		VertexShader = compile vs_3_0 VertexShaderShadow();
		PixelShader = compile ps_3_0 PS_CreateShadowMap(); 
    }
}
